/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/employeeService.ts" />
/// <reference path="../src/tms.ts" />

describe('getEmployeeList',() => {
    var injector:ng.auto.IInjectorService;
    var service:IEmployeeService;

    beforeEach(() => {
        injector = angular.injector(['ng','tms']);
        service = injector.get<IEmployeeService>('employeeService');
    });

    //常规无条件获取
    it('get employee list normal',(done) => {
        service.getList(null, null, null, null,null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 专员类型包含 调度专员 的员工列表
    it('get employee list by type \'调度专员\'',(done) => {
        service.getList('调度专员',null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('调度专员|||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 用户名包含1 的员工列表
    it('get employee list by userName \'1\'',(done) => {
        service.getList(null,'1',null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|1||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 真实姓名包含调度 的员工列表
    it('get employee list by realName \'调度 \'',(done) => {
        service.getList(null,null,'调度',null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||调度|||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 手机号包含4 的员工列表
    it('get employee list by phoneNumber \'4\'',(done) =>{
        service.getList(null,null,null,'4',null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||4||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 所属部门包含客服 的员工列表
    it('get employee list by departmentId \'客服\'',(done) =>{
        service.getList(null,null,null,null,'客服',0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||||客服|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 专员类型包含计划， 用户名包含j，真是姓名包含计划，手机号包含186, 所属部门包含客服 的员工列表
    it('get employee list by type \'计划\' and userName \'j\' and realName \'计划 \' and phoneNumber \'186\' and departmentId \'客服\' ',(done) =>{
        service.getList('计划','j','计划','186','客服',0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('计划|j|计划|186|客服|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });


    //获取员工详细
     it('get detail',(done) =>{
        service.getDetail('2').then((res) => {
            expect(res.data.userName).toBe("detail");
            expect(res.data.email).toBe("detail@qq.com");
            expect(res.data.phoneNumber).toBe("15854565852");
            expect(res.data.realName).toBe('计划');
            expect(res.data.sex).toBe(true);
            expect(res.data.isEnabled).toBe(true);
            expect(res.data.userGroupId).toBe("1");
            expect(res.data.roles.length).toBe(2);
            expect(res.data.types.length).toBe(2);
            expect(res.data.extData).toBe("2");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //添加员工
     it('add employee',(done) =>{
        service.add('丽丽','111111','111111','ll@qq.com','18355554444','李力',true,false,'2',['1','2'],['计划专员','调度专员']).then((res) => {
            expect(res.data.extData).toBe("丽丽|111111|111111|ll@qq.com|18355554444|李力|true|false|2|2|2");
            done();
        },(err) => {
            done.fail(err);
        });
    });


    //编辑员工
    it('edit employee',(done) =>{
        service.edit('2','123456','ll@qq.com','18655554433','李力',true,true,'2',['3','4'],['计划专员','客服专员']).then((res) => {
            expect(res.data.extData).toBe("2|123456|ll@qq.com|18655554433|李力|true|true|2|2|2");  
            done();
        },(err) => {
            done.fail(err);
        });
    });


});